<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<style>
#div1 {width:200px; height:200px; background:yellow; position:absolute;}
</style>
<script>
var oDiv=null;
var disX=0;
var disY=0;

window.onload=function ()
{
	oDiv=document.getElementById('div1');
	
	oDiv.onmousedown=fnDown;
};

function fnDown(ev)
{
	var oEvent=ev||event;
	
	disX=oEvent.clientX-oDiv.offsetLeft;
	disY=oEvent.clientY-oDiv.offsetTop;
	
	document.onmousemove=fnMove;
	document.onmouseup=fnUp;
}

function fnMove(ev)
{
	var oEvent=ev||event;
	
	oDiv.style.left=oEvent.clientX-disX+'px';
	oDiv.style.top=oEvent.clientY-disY+'px';
}

function fnUp()
{
	document.onmousemove=null;
	document.onmouseup=null;
}
</script>
</head>

<body>
<div id="div1"></div>
</body>
</html>
